package ru.ifmo.metopt;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import ru.ifmo.metopt.abstracts.*;

import java.util.Arrays;

/**
 * @author avhaliullin
 */
public class Launcher {
    public static void main(String[] args) {
        ApplicationContext context = new FileSystemXmlApplicationContext("metopt-config.xml");
        BeanFactory factory = (BeanFactory) context;
        switch (args[0].toLowerCase()) {
            case "restricted": {
                RestrictedTaskSolver solver = (RestrictedTaskSolver) factory.getBean("solver");
                Task task = (Task) factory.getBean("task");
                double[] result = solver.solve(task.getFunction(), task.getInitialPoint(), task.getRestrictions());
                System.out.print("Result: " + Arrays.toString(result));
            }
            break;
            case "unrestricted": {
                MultipleDimensionSolver solver = (MultipleDimensionSolver) factory.getBean("multipleDimensionSolver");
                Task task = (Task) factory.getBean("task");
                double[] result = solver.solve(task.getFunction(), task.getInitialPoint());
                System.out.print("Result: " + Arrays.toString(result));
            }
            break;
            default: {
                SingleDimensionSolver solver = (SingleDimensionSolver) factory.getBean("singleDimensionSolver");
                Function1D task = (Function1D) factory.getBean("singleDimensionFunction");
                double result = solver.solve(task);
                System.out.print("Result: " + result);
            }
        }
    }
}
